package servlet;

import Utils.io.json.JacksonUtils;
import Utils.web.BaseServlet;
import pojo.Person;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author d11yu
 */
@WebServlet(name = "AjaxServlet", value = "/AjaxServlet")
public class AjaxServlet extends BaseServlet {
    protected void jsAjax(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Ajax请求过来了");
        Person person1 = new Person(1, "马达");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        String s = JacksonUtils.getInstance().serialize(person1);
        response.getWriter().write(s);
    }

    protected void jQueryAjax(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("jQuery Ajax请求过来了");
        Person person1 = new Person(1, "马达");
        String s = JacksonUtils.getInstance().serialize(person1);
        response.getWriter().write(s);
    }

    protected void jQueryGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("jQuery Get请求过来了");
        Person person1 = new Person(1, "马达");
        String s = JacksonUtils.getInstance().serialize(person1);
        response.getWriter().write(s);
    }

    protected void jQueryPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("jQuery Post请求过来了");
        Person person1 = new Person(1, "马达");
        String s = JacksonUtils.getInstance().serialize(person1);
        response.getWriter().write(s);
    }

    protected void jQueryGetJSON(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("jQuery GetJSON请求过来了");
        Person person1 = new Person(1, "马达");
        String s = JacksonUtils.getInstance().serialize(person1);
        response.getWriter().write(s);
    }

    protected void jQuerySerialize(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("jQuery Serialize请求过来了");
        System.out.println("用户名：" + request.getParameter("username"));
        System.out.println("密码：" + request.getParameter("password"));
        Person person1 = new Person(1, "马达");
        String s = JacksonUtils.getInstance().serialize(person1);
        response.getWriter().write(s);
    }
}
